const Koa = require('koa')
const { bodyParser } = require("@koa/bodyparser");
const Router = require('@koa/router');
const userRouter = require('./routes/user')
const attractionRouter = require('./routes/attraction')
const mount = require('koa-mount');
const serve = require('koa-static')
const cors = require('@koa/cors');
const {sequelize} = require('./database/index')

const app = new Koa()

;(async function(){
    sequelize.sync({ force: false })
})()

app.use(cors({
    origin(ctx) {
        return '*';
    }
}));
app.use(mount('/img', serve(__dirname + '/upload/images')));
const router = new Router(); //总路由
app.use(bodyParser());

router.use('/user', userRouter.routes(), userRouter.allowedMethods())
router.use('/attraction', attractionRouter.routes(), attractionRouter.allowedMethods())

app
    .use(router.routes())
    .use(router.allowedMethods());

app.listen(3000)